#!/bin/bash

hive_db_name=waterflow
mysql_db_name=bg_waterflow_report

starttime=`date +'%Y-%m-%d %H:%M:%S'`

export_data() {
/opt/module_no_kerberos/sqoop-1.4.6/bin/sqoop export \
--connect "jdbc:mysql://hadoop102:3306/${mysql_db_name}?useUnicode=true&characterEncoding=utf-8"  \
--username root \
--password 123456 \
--table $1 \
--num-mappers 1 \
--export-dir /warehouse/$hive_db_name/ads/$1 \
--input-fields-terminated-by "\t" \
--update-mode allowinsert \
--update-key $2 \
--input-null-string '\\N'    \
--input-null-non-string '\\N'
}

case $1 in
  "ads_region_waterflow" )
    export_data "ads_region_waterflow" "datetime,Region_ID"
  ;;
  "all" )
    export_data "ads_region_waterflow" "datetime,Region_ID"
  ;;
esac

endtime=`date +'%Y-%m-%d %H:%M:%S'`
start_seconds=$(date --date="$starttime" +%s);
end_seconds=$(date --date="$endtime" +%s);
echo "本次运行时间: "$((end_seconds-start_seconds))"s"
